<template>
	<span class="app-control-tree__node__icon">
		<template v-if="iconCustomCode && iconScriptCode">
			<span :domPropsInnerHtml="getCustomIcon(iconScriptCode)"></span>
		</template>
		<template v-else-if="cssClass">
			<i :class="cssClass"></i>
		</template>
		<template v-else-if="imagePath">
			<img :src="imagePath" />
		</template>
		<template v-else-if="showDefaultIcon">
			<FileTextOutlined />
		</template>
	</span>
</template>

<script setup lang="ts">
import { treeNodeIconProps } from '../tree';
import { FileTextOutlined } from '@ant-design/icons-vue';
const props = defineProps(treeNodeIconProps);
const emit = defineEmits(['itemClick']);

const getCustomIcon = (scriptCode: string): string => {
	let icon = '';
	const code = scriptCode.replace(new RegExp('return', 'g'), `icon =`);
	eval(code);
	return icon;
};
</script>
